package com.dragon.pear.common.application;

import com.chris.dev.base.libs.v1.http.protocols.HttpHeader;
import com.chris.libs.base.x.mvpp.application.BaseApplication;
import com.chris.libs.devtools.x.v1.utils.UtilsManager;
import com.chris.libs.http.x.v1.NetApi;

import java.util.Random;

/**
 * @author Chris chan
 * Create on： 2025/2/1 9:59
 * Use for:
 * Explain:
 */
public class PearApplication extends BaseApplication {
    @Override
    protected void init() {
        UtilsManager.init(getApplicationContext());
        initNetProtocol();
        //全局Token 不合适
//        NetClient.addInterceptor(chain -> {
//            Request request = chain.request()
//                    .newBuilder()
//                    .addHeader("Authorization", "Bearer thismyauthorizationtoken")
//                    .build();
//            return chain.proceed(request);
//        });
    }

    /**
     * 初始化网络协议
     */
    private void initNetProtocol() {
        HttpHeader httpHeader = HttpHeader.create()
                .setOs("Android")
                .setVer("1.0.0")
                .setChannel("OPPO")
                .setAppId("Worker")//应该采用算法加密
                .setAppSecret("Worker Android");//应该采用算法加密
        // 业务干预修改经纬度
        NetApi.PostHeaderCallback callback = header -> {
            long lng1 = new Random().nextInt(1000000);
            long lat1 = new Random().nextInt(1000000);
            header.setLng(107000000L + lng1);
            header.setLat(33000000L + lat1);
        };
        NetApi.initHeader(httpHeader, callback);
    }
}
